
//
//  WZHTTPClient.swift
//  weibo
//
//  Created by mac on 16/3/9.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import AFNetworking

enum requstType:Int{
    
    case GET = 0
    case POST = 1
}

class WZHTTPClient: AFHTTPSessionManager {

    static let shareInstance:WZHTTPClient = {
    let manager = WZHTTPClient()
        manager.responseSerializer.acceptableContentTypes?.insert("text/plain")
    
    return manager
    }()
//   对外提供一个方法加载请求
    
    func loadRequest(loadRequestType:requstType,URLString:String,parameters: AnyObject?,success:(JSON:AnyObject?)->(),faile:(error:ErrorType)->()){
        
        
        if loadRequestType.rawValue == 0{//get
            
           self.GET(URLString, parameters: parameters, progress: nil, success: { (_, JSON) -> Void in
            success(JSON: JSON)
                }, failure: { (_, error) -> Void in
                  faile(error: error)
            })
            
            
        }else if loadRequestType.rawValue == 1{//post
            self.POST(URLString, parameters: parameters, progress: nil, success: { (_, JSON) -> Void in
                success(JSON: JSON)
                }, failure: { (_, error) -> Void in
                     faile(error: error)
            })
        }
        
    }
}
